package homework;

/**
 * @author green-citrus
 * @version 1.0
 */
public class Person {
    private String name;
    private Vehicles vehicles;

    //在创建人对象时，事先给他分配一个交通工具
    public Person(String name, Vehicles vehicles) {
        this.name = name;
        this.vehicles = vehicles;
    }

    //实例化Person对象"唐僧"，要求一般情况下用Horse作为交通工具，遇到大河时用Boat作为交通工具
    //思路：可以把具体的要求，封装成方法
    public void passRiver() {
        //得到船
        //判断一下，当前的 vehicles 属性是null或不是船，就获取一艘船
        //vehicles = null 时，vehicles instanceof Boat 为false
        if(!(vehicles instanceof Boat))
        {
            vehicles = VehiclesFactory.getBoat();
        }
        vehicles.work();
    }

    public void common() {
        //得到马儿
        //判断一下，当前的 vehicles 属性是null或不是马，就获取一匹马
         if(!(vehicles instanceof Horse)) {
             vehicles = VehiclesFactory.getHorse();
         }
         vehicles.work();
    }

    public void passFireHill() {
        if(!(vehicles instanceof Plane)) {
            vehicles = VehiclesFactory.getPlane();
        }
        vehicles.work();
    }
}
